/*
 * MenuItem.java
 * Created on December 20, 2007, 1:38 AM by Uru
 *
 * An item in a menu
 */

package MenuSystem;

import java.awt.*;
import javax.swing.*;
import java.awt.image.*;

public class GameMenuItem{
    //data section
    int x;              //the x position of the object
    int y;              //the y position of the object
    SelfDrawing content;//the object is determined by the type
    float opacity;      //the opacity level of the object
    boolean active;     //should this item be displayed?

    //Creates a new instance of an generic MenuItem
    //useful for programmers creating new types of menu item
    public GameMenuItem(int px, int py, SelfDrawing sd, float opac, boolean act){
        x = px;
        y = py;
        content = sd;
        opacity = opac;
        active = act;
    }
    
    //Creates a new instance of an image MenuItem
    public GameMenuItem(int px, int py, Image img, float opac, boolean act){
        x = px;
        y = py;
        content = new DisplayImage(img);
        opacity = opac;
        active = act;
    }
    
    //Creates a new instance of a rectangle MenuItem
    public GameMenuItem(int px, int py, int w, int h, Color c, boolean fill, float opac, boolean act){
        x = px;
        y = py;
        content = new DisplayRectangle(w,h,fill,c);
        opacity = opac;
        active = act;
    }
    
    //Creates a new instance of a text MenuItem
    public GameMenuItem(int px, int py, String t, Font f, Color c, float opac, boolean act){
        x = px;
        y = py;
        content = new DisplayText(t,f,c);
        opacity = opac;
        active = act;
    }
    
    public void draw(Graphics2D g, int mx, int my, JComponent screen){
        if(active){
            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
            content.draw(g,mx+x,my+y,screen);
            g.setComposite(AlphaComposite.SrcOver);
        }
    }
    
    public void setActive(boolean act){
        active = act;
    }
    
    public boolean isActive(){
        return active;
    }
    
    public void setOpacity(float opac){
        opacity = opac;
    }
    
    public float getOpacity(){
        return opacity;
    }
}
